/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template sigFile, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.server;

import cn.ac.iie.di.datadock.rdata.exchange.client.core.REFieldType;
import cn.ac.iie.di.datadock.rdata.exchange.client.v1.REMessage;
import cn.ac.iie.di.news.JsonNewsSender;
import cn.ac.iie.di.global.GlobalParas;
//import static cn.ac.iie.di.global.GlobalParas.init;
import cn.ac.iie.di.msg.JsonMsgSender;
import cn.ac.iie.di.rocketmq.Message;
import cn.ac.iie.di.rocketmq.RocketMqClient;
import static cn.ac.iie.di.rocketmq.RocketMqClient.log;
import static cn.ac.iie.di.rocketmq.RocketMqClient.oriMq;
import cn.ac.iie.di.tools.JsonSplitor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import cn.ac.iie.di.tools.ScriptTool;

/**
 *
 * @author lenovo-pc
 */
public class ZZPTParserStartup {

    static Logger logger = null;

    static {
        PropertyConfigurator.configure(ClassLoader.getSystemClassLoader().getResource("log4j.properties"));
        logger = Logger.getLogger(ZZPTParserStartup.class.getName());
    }

    public static void main(String[] args) {
//        init();
//        offer();
//
        startParser();
        startSender();
        startPull();
        startKeepGrafanaAlive();
    }
    
    public static Message offer() {
        REFieldType[] types={REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,
        REFieldType.String,REFieldType.Strings,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String,REFieldType.String};
        
//        appStore
//        String[] colNames = {"key","msg_type","APPSTORENAME","APPSTOREID","WECHATID","COMPANY","APPSTORELOGO","APPSTOREINFO","PUBLISHTIME","SNAPSHOTTIME","POPULARAPPLIST","NEWPOPULARAPPLIST","HOTSEARCH","ISDEL","DELTIME"};
//        List<Object[]> dataList = new ArrayList<Object[]>();
//        Object[]data={"1234567890","appstore.basicinfo","5b+r5pKt","001","快播微信公众号","深圳快播科技有限股份公司","MTIzNDUuanBn","5bim5p2l5b+r5LmQ","20170101000000","20170102000000",new String[0],new String[0],new String[0],"0","20170103000000"};
//        dataList.add(data);
        
//        appCategory
//        String[] colNames = {"msg_type","APPCATEGORYID","APPSTOREID","APPCATEGORY","CATEGORYINFO","SNAPSHOTTIME","BARDIR","APPNUM","ISDEL","DELTIME"};
//        List<Object[]> dataList = new ArrayList<Object[]>();
//        Object[]data={"appstore.appcategory","MTAwODY=","002","5a2m5Lmg5bqU55So","5a2m5Lmg","20170101000000","56eR5pmu","99","0","20170101000000"};
//        dataList.add(data);
//        
//        appInfo
        String[] colNames = {"key","msg_type","APPID","APPNAME","APPPNAME","APPSTOREID","APPVERSION","APPCATEGORYID","APPINFO","SNAPSHOTTIME","APPUPDATETIME","APPSCORE","APPUERRNUM","APPSIZE","APPOWNER","APPINSTALLREQUEST","APPSNAPSHOTURLS","USERIDLIST","USERNUM","APPLOGOURL","APPSTATE","APPHARMSTATE","APPHARMMSG","APPIP","APPIPLOCAL","APPDOWNLOADURL","ISDEL","DELTIME"};
        List<Object[]> dataList = new ArrayList<Object[]>();
        Object[]data={"1234567890","appstore.app","MDAz","5b+r5pKt","5b+r5pKt5a6J6KOF5YyF","003","MS4w","MDAx","5bim57uZ5L2g5b+r5LmQ","20170101000000","20170101100000","10","999999999","200","5aSp5omN","5LiN6ZyA6KaB","d3d3Lmt1YWliby5jb20=","","650000000","http://p16.qhimg.com/t013bd603ddb99329f4.jpg","0","0","挺健康","MTkyLjE2Ny4xMS4xNzE=","MTkyLjE2Ny4xMS4xNzEuMTAwODY=","d3d3LmJhaWR1LmNvbQ==","0","20170104000000"};
        dataList.add(data);
//        
//        appComment
//        String[] colNames = {"msg_type","COMMENTID","APPSTOREID","APPVERSION","APPID","TEXT","PUBLISHTIME","SNAPSHOTTIME","POSTNUM","PRAISEDNUM","PUBLISHFLOOR","ISDEL","DELTIME"};
//        List<Object[]> dataList = new ArrayList<Object[]>();
//        Object[]data={"appstore.appcomments","MDAx","001","MS4w","MTAwMQ==","5b6I5aW95b6I5by65aSn","20170101000000","20170101000000","10000","20000","10","0","20170101100000"};
//        dataList.add(data);
//        
//        appDeveloper
//        String[] colNames = {"msg_type","APPID","APPSTOREID","APPVERSION","COMPANYNAME","COMPANYCERTIFICATETYPE","COMPANYCERTIFICATEID","LEGALNAME","COMPANYPHONENUM","COMPANYPROVINCE","COMPANYCITY","COMPANYDISTRICT","COMPANYDETAILADDRESS","PERSIONNAME","PERSIONCERTIFICATETYPE","PERSIONCERTIFICATEID","PERSIONPHONENUM","PERSIONPROVINCE","PERSIONCITY","PERSIONDISTRICT","PERSIONDETAILADDRESS","CONTACTNAME","CONTACTPHONE","CONTACTIDCARD","SNAPSHOTTIME"};
//        List<Object[]> dataList = new ArrayList<Object[]>();
//        Object[]data={"appstore.appcompany","MS4w","001","MDAz","5rex5Zyz5b+r5pKt==","100021","MTAwODY=","于健","110","5bm/5Lic55yB","5bm/5bee","5rex5Zyz","5b+r5pKt5Y6/","5rex5Zyz5b+r5pKt5aSn5qW8","5LqO5YGl","110109231514312","111","13093210231","5YyX5Lqs","5YyX5Lqs","5YyX5Lqs","5LiJ6YeM5bGv","5LqO5YGl","",""};
//        dataList.add(data);
        
        String docSchemaName = null;
        Map<String, String> userDesc = null;
        Message msg = new Message(colNames,types,dataList,docSchemaName,userDesc);
       
        log.info("get " + msg.getData().size() + " message from testdata");
//        try {
//            GlobalParas.PULL_MQ_QUEUE.put(msg);
//        } catch (InterruptedException ex) {
//            log.error(ex, ex);
//        }
        return msg;
    }
    
    public static void startParser() {

        Thread threadfans = new Thread(new JsonNewsSender());
        threadfans.setName("JsonNewsSender");
        threadfans.start();

    }

    public static void startPull() {

        Thread recvMessageThread = new Thread(new RocketMqClient(GlobalParas.POLL_MQ_NAME));
        recvMessageThread.setName("PollMessage");
        recvMessageThread.start();

    }

    public static void startSender() {

        try {
            Thread new1Thread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_NEWS1, GlobalParas.TYPE_NEWS, GlobalParas.NEWS1_QUEUE, "JsonNew1Task", "1"));
            new1Thread.setName("JsonNew1Sender");
            new1Thread.start();
            Thread.sleep(5000);
            Thread new2Thread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_NEWS2, GlobalParas.TYPE_NEWS, GlobalParas.NEWS2_QUEUE, "JsonNew2Task", "3"));
            new2Thread.setName("JsonNew2Sender");
            new2Thread.start();
            Thread.sleep(5000);
            Thread comment1Thread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_COMMENT1, GlobalParas.TYPE_COMMENT, GlobalParas.COMMENT1_QUEUE, "JsonComment1Task", "2"));
            comment1Thread.setName("JsonComment1Sender");
            comment1Thread.start();
            Thread.sleep(5000);
            Thread comment2Thread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_COMMENT2, GlobalParas.TYPE_COMMENT, GlobalParas.COMMENT2_QUEUE, "JsonComment2Task", "4"));
            comment2Thread.setName("JsonComment2Sender");
            comment2Thread.start();
            Thread.sleep(5000);
            Thread userThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_USER, GlobalParas.TYPE_USER, GlobalParas.USER_QUEUE, "JsonUSERTask", "5"));
            userThread.setName("JsonUSERSender");
            userThread.start();
            Thread.sleep(5000);
                 
            Thread appStoreThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_APP_STROE, GlobalParas.TYPE_APP_STORE, GlobalParas.APP_STORE_QUEUE, "JsonAppStoreTask", "appstore.basicinfo"));
            appStoreThread.setName("JsonAppStoreSender");
            appStoreThread.start();
            Thread.sleep(5000);
           
            Thread appCategoryThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_APP_CATEGORY, GlobalParas.TYPE_APP_CATEGORY, GlobalParas.APP_CATEGORY_QUEUE, "JsonAppCategoryTask", "appstore.appcategory"));
            appCategoryThread.setName("JsonAppCategorySender");
            appCategoryThread.start();
            Thread.sleep(5000);
          
            Thread appInfoThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_APP_INFO, GlobalParas.TYPE_APP_INFO, GlobalParas.APP_INFO_QUEUE, "JsonAppInfoTask", "appstore.app"));
            appInfoThread.setName("JsonAppInfoSender");
            appInfoThread.start(); 
            Thread.sleep(5000);
      
            Thread appCommentThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_APP_COMMENT, GlobalParas.TYPE_APP_COMMENT, GlobalParas.APP_COMMENT_QUEUE, "JsonAppCommentTask", "appstore.appcomments"));
            appCommentThread.setName("JsonAppCommentSender");
            appCommentThread.start();
            Thread.sleep(5000);
            
            Thread appDeveloperThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_APP_DEVELOPER, GlobalParas.TYPE_APP_DEVELOPER, GlobalParas.APP_DEVELOPER_QUEUE, "JsonAppDeveloperTask", "appstore.appcompany"));
            appDeveloperThread.setName("JsonAppDeveloperSender");
            appDeveloperThread.start();
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            java.util.logging.Logger.getLogger(ZZPTParserStartup.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void startKeepGrafanaAlive(){
        ScriptTool scriptTool=new ScriptTool();
        new Thread(scriptTool).start();
    }

}
